5.2.áVirtual Disk Image (VDI) files

By default, VirtualBox uses its own container format for guest hard disks -- Virtual Disk Image (VDI) files.

The VDI files reside on the host system and are seen by the guest systems as hard disks of a certain geometry. When creating an image, its size has to be specified, which determines this fixed geometry. It is therefore not possible to change the size of the virtual hard disk later.

As briefly mentioned in Sectioná3.2, “Creating a virtual machine”, there are two options of how to create the image: fixed-size or dynamically expanding.

For either of the above two image types (that is, irrespective of whether an image is fixed-size or dynamically expanding), you can also specify whether write operations affect the image directly.

  1. With normal images (the default setting), there are no restrictions on how guests can read from and write to the disk. Because of this, a normal hard disk can only be attached to a single virtual machine at any given time (although you can detach them from a VM and attach them to another).

    When you take a snapshot of your virtual machine as described in Sectioná3.4.4, “Snapshots”, the state of such a "normal hard disk" will be recorded together with the snapshot, and when reverting to the snapshot, its state will be fully reset.

  2. By contrast, immutable images are read-only and can be used from multiple virtual machines simultaneously. Write accesses to immutable hard disks will be directed to a special differencing disk image which VirtualBox creates automatically. However, when you shut down the VM to which the immutable disk is attached, the changes in the differencing disk will be completely discarded.

    Clearly, creating an immutable virtual disk image makes no sense, because then the hard disk would always be reset to an empty state when its VM is shut down.

    Hence, you will ordinarily create a "normal" virtual disk image and then, when its contents are deemed useful, mark it immutable. For reasons of data consistency, it is presently not possible to change the type of a hard disk disk image that is currently registered. As a result, first remove the existing image from VirtualBox's list of registered images using VBoxManage unregisterimage and then re-register the image using VBoxManage registerimage, adding the -type immutable parameter; see Sectioná8.10, “VBoxManage registerimage / unregisterimage”.

  3. Finally, write-through hard disks are like normal hard disks in that they fully support read and write operations also. However, their state is not saved when a snapshot is taken, and not restored when a VM's state is reverted.

    To create a disk image as "write-through", use the VBoxManage createvdi command; see Sectioná8.12, “VBoxManage createvdi”. To mark an existing image as write-through, unregister and re-register the image as previously described, but add -type writethrough.

To illustrate the differences between the various types with respect to snapshots: You have installed your guest operating system in your VM, and you have taken a snapshot. Imagine you have accidentally infected your VM with a virus and would like to go back to the snapshot. With a normal hard disk image, you simply revert the state of the VM, and the earlier state of your hard disk image will be restored as well (and your virus infection will be undone). With an immutable hard disk, irrespective of the snapshot, all it takes is to shut down your VM, and the virus infection will be discarded. With a write-through image however, you cannot easily undo the virus infection by means of virtualization, but will have to disinfect your virtual machine like a real computer.

Still, you might find write-though images useful if you want to preserve critical data irrespective of snapshots, and since you can attach more than one VDI to a VM, you may want to have one immutable for the operating system and one write-through for your data files.